Skip to content

feat: wire regex support into CLI — UX messaging, --regex-hint, docs, homepage#114

Merged
shouze merged 9 commits intomainfrom
feat/regex-cli
Mar 13, 2026
Merged

feat: wire regex support into CLI — UX messaging, --regex-hint, docs, homepage#114
shouze merged 9 commits intomainfrom
feat/regex-cli

Conversation

@shouze
Copy link
Contributor

@shouze shouze commented Mar 12, 2026

Closes #112
Depends on #111 (already merged via feat/regex-core)

Root cause / context

The GitHub REST API does not support /pattern/flags regex syntax. Issue #111 added the core src/regex.ts module + aggregate() filter. This PR wires that into the CLI and documents it end-to-end.

What changed

CLI (github-code-search.ts)

  • Detect regex queries via isRegexQuery() and derive the API query + client-side filter via buildApiQuery()
  • Pass regexFilter down to aggregate()
  • Print a dim UX warning when the query has been broadened (e.g. /axios": "1\.12/ → API receives axios)
  • Add --regex-hint <term> escape hatch to override the auto-derived literal seed

Highlight fix (src/aggregate.ts)

  • When regexFilter is active, replace API-provided TextMatchSegment[] (pointing at the literal seed) with segments recomputed from actual regex match positions in each fragment
  • TextMatch entries where the regex finds no match are also filtered out
  • 3 new test cases: exact segment positions, multiline line/col computation, partial filtering

Docs

  • docs/usage/search-syntax.md — new Regex queries section with 4 examples + tip/warning admonitions
  • docs/reference/cli-options.md--regex-hint flag documented
  • docs/architecture/components.mdsrc/regex.ts added to C4 Level 3a diagram
  • AGENTS.md — module map entry + symptom table row for src/regex.ts
  • README.md — Regex search use case

Homepage

  • ComparisonTable.vue — new row Regex queries (/pattern/flags): ✗ gh search code (REST API), ✓ github-code-search — note clarifies GitHub supports regex in the web UI only
  • UseCaseTabs.vue — new tab Semver / version audit illustrating /\"axios\": \"1./ for finding repos pinned to a vulnerable minor version

How to test

# Regex with top-level alternation
github-code-search query '/import (axios|got)/' --org <org>

# Semver pin audit
github-code-search query '/"axios": "1\./' --org <org>

# Manual hint override
github-code-search query '/[Aa]xios/' --org <org> --regex-hint axios

Validation

bun test        → 642 pass, 0 fail
bun run lint    → 0 errors
bun run format:check → no diff
bun run knip    → no issues

Copilot AI review requested due to automatic review settings March 12, 2026 14:03
@github-actions
Copy link

Coverage after merging feat/regex-cli into main will be

96.51%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.55%100%100%93.86%318–322, 383, 400, 63–69
   cache.ts98.08%100%100%97.87%28
   completions.ts99.35%100%100%99.29%252
   group.ts100%100%100%100%
   output.ts99.12%100%94.74%99.52%58
   regex.ts98.50%100%100%98.39%117, 217
   render.ts94.26%100%89.47%94.49%158, 182–187, 189–191, 193–194, 245–246, 267, 440–441, 523–527
   upgrade.ts88.46%100%94.44%87.89%127–128, 148–155, 158–164, 169, 174, 210–213
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   rows.ts97.58%100%100%97.44%168, 54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%

@github-actions
Copy link

github-actions bot commented Mar 12, 2026

🔦 Lighthouse Report

Page ⚡ Perf ♿ A11y 🛡️ BP 🔍 SEO Report
/github-code-search/ 🟢 98 (≥97) 🟢 100 (≥99) 🟢 100 (≥99) 🟢 100 (≥99) 🔗 view
/github-code-search/getting-started/ 🟢 99 (≥97) 🟢 100 (≥99) 🟢 100 (≥99) 🟢 100 (≥99) 🔗 view

Thresholds: Perf ≥ 97 · A11y ≥ 99 · BP ≥ 99 · SEO ≥ 99
commit 80908ee · full workflow run

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds first-class “regex query” support to github-code-search by translating /pattern/flags queries into a safe GitHub REST API query plus a local post-filter, and updates aggregation/highlighting so match segments align with actual regex matches.

Changes:

  • Introduces src/regex.ts to detect /pattern/flags, derive an API search term (incl. top-level alternation → OR), and compile a local RegExp.
  • Extends the CLI with --regex-hint and wires regex parsing into the search flow; updates aggregation to recompute TextMatchSegments from the regex matches.
  • Updates docs/README and UI docs components to document and showcase regex queries; adds tests for the new behavior.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/regex.ts New regex-query parser: extracts regex token, derives API term, returns compiled RegExp for local filtering.
src/regex.test.ts Unit tests for regex detection and API-term derivation behavior.
src/aggregate.ts Adds optional regexFilter path to drop non-matching fragments and recompute match segments from regex results.
src/aggregate.test.ts Tests repo/file filtering under regexFilter and validates recomputed segment indices/line/col.
github-code-search.ts Adds --regex-hint and integrates regex mode into the CLI search pipeline.
README.md Documents regex search as a new use case with an example invocation.
docs/usage/search-syntax.md Adds a dedicated “Regex queries” section with examples, hints, and caveats.
docs/reference/cli-options.md Adds --regex-hint to the CLI options reference.
docs/architecture/components.md Updates the C4 component diagram to include the new regex parser component.
docs/.vitepress/theme/UseCaseTabs.vue Adds a “Semver / version audit” use case tab using regex query syntax.
docs/.vitepress/theme/ComparisonTable.vue Adds “Regex queries” as a comparison feature and links to docs.
AGENTS.md Documents the new src/regex.ts module in the repository map.

shouze added 2 commits March 13, 2026 11:11
When a regex query is active, the GitHub API returns TextMatchSegments
pointing at the literal search term (e.g. 'axios'), not at the full
regex match ('axios": "1.12'). highlightFragment() was therefore
bold-yellowing only the literal fragment.

Fix: in aggregate(), when regexFilter is set, run the regex against each
fragment and replace API-provided segments with TextMatchSegments derived
from the actual regex match positions (correct 1-based line/col).
TextMatch entries where the regex finds no match are filtered out.

Add 3 new test cases: exact segment positions, multiline line/col, and
partial textMatches filtering.

Closes part of #112
- Parse /pattern/flags in query subcommand via isRegexQuery() / buildApiQuery()
- Pass regexFilter to aggregate(); display UX warning when query is broadened
- Add --regex-hint <term> escape hatch for edge cases
- docs/usage/search-syntax.md: new Regex queries section with 4 examples
- docs/reference/cli-options.md: document --regex-hint flag
- docs/architecture/components.md: add src/regex.ts to C4 Level 3a diagram
- docs/.vitepress/theme/ComparisonTable.vue: add Regex queries row (web UI only note)
- docs/.vitepress/theme/UseCaseTabs.vue: add Semver / version audit use case
- AGENTS.md: add src/regex.ts entry + symptom table row
- README.md: add Regex search use case

Closes #112
@github-actions
Copy link

Coverage after merging feat/regex-cli into main will be

96.56%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.55%100%100%93.86%318–322, 383, 400, 63–69
   cache.ts98.08%100%100%97.87%28
   completions.ts99.35%100%100%99.29%252
   group.ts100%100%100%100%
   output.ts99.12%100%94.74%99.52%58
   regex.ts99.26%100%100%99.21%251
   render.ts94.26%100%89.47%94.49%158, 182–187, 189–191, 193–194, 245–246, 267, 440–441, 523–527
   upgrade.ts88.46%100%94.44%87.89%127–128, 148–155, 158–164, 169, 174, 210–213
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   rows.ts97.58%100%100%97.44%168, 54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

@github-actions
Copy link

Coverage after merging feat/regex-cli into main will be

96.57%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.55%100%100%93.86%318–322, 383, 400, 63–69
   cache.ts98.08%100%100%97.87%28
   completions.ts99.35%100%100%99.29%252
   group.ts100%100%100%100%
   output.ts99.12%100%94.74%99.52%58
   regex.ts99.26%100%100%99.21%251
   render.ts94.26%100%89.47%94.49%158, 182–187, 189–191, 193–194, 245–246, 267, 440–441, 523–527
   upgrade.ts88.46%100%94.44%87.89%127–128, 148–155, 158–164, 169, 174, 210–213
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   rows.ts97.58%100%100%97.44%168, 54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

…ror, completions --regex-hint, fix comment
@github-actions
Copy link

Coverage after merging feat/regex-cli into main will be

96.60%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.55%100%100%93.86%318–322, 383, 400, 63–69
   cache.ts98.08%100%100%97.87%28
   completions.ts99.38%100%100%99.32%258
   group.ts100%100%100%100%
   output.ts99.12%100%94.74%99.52%58
   regex.ts99.26%100%100%99.21%251
   render.ts94.26%100%89.47%94.49%158, 182–187, 189–191, 193–194, 245–246, 267, 440–441, 523–527
   upgrade.ts88.46%100%94.44%87.89%127–128, 148–155, 158–164, 169, 174, 210–213
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   rows.ts97.58%100%100%97.44%168, 54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

@github-actions
Copy link

Coverage after merging feat/regex-cli into main will be

96.60%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.55%100%100%93.86%318–322, 383, 400, 63–69
   cache.ts98.08%100%100%97.87%28
   completions.ts99.38%100%100%99.32%258
   group.ts100%100%100%100%
   output.ts99.13%100%94.74%99.52%61
   regex.ts99.26%100%100%99.21%251
   render.ts94.26%100%89.47%94.49%158, 182–187, 189–191, 193–194, 245–246, 267, 440–441, 523–527
   upgrade.ts88.46%100%94.44%87.89%127–128, 148–155, 158–164, 169, 174, 210–213
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   rows.ts97.58%100%100%97.44%168, 54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

@shouze shouze requested a review from Copilot March 13, 2026 18:21
@github-actions
Copy link

Coverage after merging feat/regex-cli into main will be

96.60%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.55%100%100%93.86%318–322, 383, 400, 63–69
   cache.ts98.08%100%100%97.87%28
   completions.ts99.38%100%100%99.32%258
   group.ts100%100%100%100%
   output.ts99.13%100%94.74%99.52%61
   regex.ts99.26%100%100%99.21%251
   render.ts94.26%100%89.47%94.49%158, 182–187, 189–191, 193–194, 245–246, 267, 440–441, 523–527
   upgrade.ts88.46%100%94.44%87.89%127–128, 148–155, 158–164, 169, 174, 210–213
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   rows.ts97.58%100%100%97.44%168, 54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.

@github-actions
Copy link

Coverage after merging feat/regex-cli into main will be

96.61%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.55%100%100%93.86%318–322, 383, 400, 63–69
   cache.ts98.08%100%100%97.87%28
   completions.ts99.38%100%100%99.32%258
   group.ts100%100%100%100%
   output.ts99.13%100%94.74%99.52%61
   regex.ts99.26%100%100%99.21%251
   render.ts94.26%100%89.47%94.49%158, 182–187, 189–191, 193–194, 245–246, 267, 440–441, 523–527
   upgrade.ts88.46%100%94.44%87.89%127–128, 148–155, 158–164, 169, 174, 210–213
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   rows.ts97.58%100%100%97.44%168, 54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 17 changed files in this pull request and generated 4 comments.

@github-actions
Copy link

Coverage after merging feat/regex-cli into main will be

96.61%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.55%100%100%93.86%318–322, 383, 400, 63–69
   cache.ts98.08%100%100%97.87%28
   completions.ts99.38%100%100%99.32%258
   group.ts100%100%100%100%
   output.ts99.13%100%95%99.52%66
   regex.ts99.26%100%100%99.21%251
   render.ts94.26%100%89.47%94.49%158, 182–187, 189–191, 193–194, 245–246, 267, 440–441, 523–527
   upgrade.ts88.46%100%94.44%87.89%127–128, 148–155, 158–164, 169, 174, 210–213
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   rows.ts97.58%100%100%97.44%168, 54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%

@shouze shouze requested a review from Copilot March 13, 2026 19:00
@shouze shouze merged commit 624c4fc into main Mar 13, 2026
11 checks passed
@shouze shouze deleted the feat/regex-cli branch March 13, 2026 19:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 18 changed files in this pull request and generated 5 comments.

Comment on lines 23 to +26
/** Options that affect the generated replay command. */
/** Wraps `s` in POSIX single quotes, escaping any embedded single quotes as '\''.
* Produces output that is safe to paste into bash / zsh regardless of the
* content (no `$()`, backtick, or glob expansion). */
Comment on lines 51 to 55
): string {
const { format, outputType, includeArchived, groupByTeamPrefix } = options;
const parts: string[] = [
`github-code-search ${JSON.stringify(query)} --org ${org} --no-interactive`,
];
const { format, outputType, includeArchived, groupByTeamPrefix, regexHint } = options;
const parts: string[] = [`github-code-search ${shellQuote(query)} --org ${org} --no-interactive`];

const excludedReposList: string[] = [...excludedRepos].map((r) => shortRepo(r, org));
Comment on lines +6 to +7
/** 1-based absolute file line (computed by api.ts / recomputeSegments in aggregate.ts).
* Used for `#L{line}` GitHub anchors in output.ts. */

```mermaid
%%{init: {"theme": "base", "themeVariables": {"fontFamily": "Poppins, Aestetico, Arial, sans-serif", "primaryColor": "#66CCFF", "primaryTextColor": "#000000", "lineColor": "#0000CC", "tertiaryColor": "#FFCC33"}, "themeCSS": ".label,.nodeLabel,.cluster-label > span{font-family:Poppins,Arial,sans-serif;letter-spacing:.2px} .cluster-label > span{font-weight:600;font-size:13px} .edgePath .path{stroke-width:2px}"}}%%
%%{init: {"theme": "base", "themeVariables": {"fontFamily": "Poppins, Aestetico, Arial, sans-serif", "primaryColor": "#9933FF", "primaryTextColor": "#ffffff", "lineColor": "#0000CC", "tertiaryColor": "#FFCC33"}, "themeCSS": ".label,.nodeLabel,.cluster-label > span{font-family:Poppins,Arial,sans-serif;letter-spacing:.2px} .cluster-label > span{font-weight:600;font-size:13px} .edgePath .path{stroke-width:2px}"}}%%
Comment on lines 53 to 55
```mermaid
%%{init: {"theme": "base", "themeVariables": {"fontFamily": "Poppins, Aestetico, Arial, sans-serif", "primaryColor": "#66CCFF", "primaryTextColor": "#000000", "lineColor": "#0000CC", "tertiaryColor": "#FFCC33"}, "themeCSS": ".label,.nodeLabel,.cluster-label > span{font-family:Poppins,Arial,sans-serif;letter-spacing:.2px} .cluster-label > span{font-weight:600;font-size:13px} .edgePath .path{stroke-width:2px}"}}%%
%%{init: {"theme": "base", "themeVariables": {"fontFamily": "Poppins, Aestetico, Arial, sans-serif", "primaryColor": "#9933FF", "primaryTextColor": "#ffffff", "lineColor": "#0000CC", "tertiaryColor": "#FFCC33"}, "themeCSS": ".label,.nodeLabel,.cluster-label > span{font-family:Poppins,Arial,sans-serif;letter-spacing:.2px} .cluster-label > span{font-weight:600;font-size:13px} .edgePath .path{stroke-width:2px}"}}%%
C4Component
@shouze shouze mentioned this pull request Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: wire regex support into CLI — UX messaging, --regex-hint option, docs, C4 diagrams

2 participants